package auth

//import "github.com/EDDYCJY/go-gin-example/models"

import (
	//"database/sql/driver"
	"web/global"
	m_user "web/models"

	"gorm.io/gorm"
)

type Auth struct {
	Username string
	Password string
}

func (this *Auth) Check() (bool, error) {
	return this.CheckAuth(this.Username, this.Password)
}

func (this *Auth) CheckAuth(username, password string) (bool, error) {
	var auth m_user.Auth
	// 假设 app.DB 是 *gorm.DB 类型的数据库连接实例
	err := global.DB.Select("id").Where("username = ? AND password = ?", username, password).First(&auth).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		return false, err
	}

	if auth.ID > 0 {
		return true, nil
	}

	return false, nil
}
